package com.mysoft.aiot.plugin.feign;

import com.mysoft.aiot.plugin.feign.model.FeignClientClass;
import com.mysoft.aiot.plugin.feign.model.FeignText;
import freemarker.template.TemplateException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassResolver
 *
 */
public class ClassResolver {

  public static List<FeignText> resolveFeignClientClassList(
      List<FeignClientClass> feignClientClasses) throws IOException, TemplateException {

    List<FeignText> pathAndFileContents = new ArrayList<>();

    for (FeignClientClass feignClientClass : feignClientClasses) {

      // 生成feign接口
      String feignClient = TemplateProcessor.parseFeignClient(feignClientClass);

      FeignText pathAndFileContent = new FeignText();

      pathAndFileContent.setText(feignClient);
      pathAndFileContent.setFileName(Environment.outputPackage.replace('.', '/') + "/" + feignClientClass.getFeignClassName() + ".java");
      pathAndFileContent.setClazz(feignClientClass.getFeignClassName());

      pathAndFileContents.add(pathAndFileContent);
    }

    return pathAndFileContents;
  }
}
